package com.topica.database.task;

import com.topica.database.DataBaseHelper;
import com.topica.database.callback.OnGetLinkDownloadListener;

import android.content.Context;
import android.widget.Toast;

public class GetLinkDownloadDataCourse extends TopicaDBTask {
	private OnGetLinkDownloadListener listener;
	private String link;
	private String courseId;
	public GetLinkDownloadDataCourse(Context context,String courseId) {
		super(context);
		this.courseId = courseId;
	}

	@Override
	protected Integer doInBackground(Void... params) {
		DataBaseHelper myDbHelper = new DataBaseHelper(
				context.getApplicationContext());
		link = myDbHelper.getLinkDownloadCourse(courseId);
		myDbHelper.close();
		return OK;
	}

	@Override
	protected void onPostExecute(Integer result) {
		super.onPostExecute(result);
		if (result == OK) {
			listener.onGetLinkDownloadListener(link);
		} else {
			Toast.makeText(context.getApplicationContext(),
					"Get Link Download Error", Toast.LENGTH_SHORT).show();
		}
	}

	public void setOnGetLinkDownloadListener(OnGetLinkDownloadListener listener) {
		this.listener = listener;
	}
}
